<?php

namespace App\Console\Commands;

use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class CommandTogetherGameNotice extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $connect = 'api';
    protected $activity = 'activity';

    protected $signature = 'CommandTogetherGameNotice';

    protected $user = 'user';//用户表
    protected $togetherGameNotice = 'together_gamge_notice';//游戏公告表
    protected $xtqjNoticeTable = 'xtqj_notice';//西天取经公告$
    protected $luckDrawTable = 'luck_draw_log';//许愿池抽奖公告
    protected $equipNoticeTable = 'equip_notice';//开运装备

    
     /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '统计每个抽奖池的公告消息';


    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function handle(){
        do{
            //查询活动表中西天取经游戏公告
            $xtqjNotices = DB::connection($this->activity)->table($this->xtqjNoticeTable)->limit(5)->orderBy('created_at','DESC')->get();
            $xtqjNotices = objToArray($xtqjNotices);
            if(!empty($xtqjNotices)){
                foreach($xtqjNotices as $v){
                    $insert = [
                        'game_name' => '西天取经',
                        'user_id' => $v['user_id'],
                        'game_type' => 2,//游戏类型1=全家总动员 2=西天取经 3=开运装备 4=荒漠捕牛 5=许愿池
                        'content' => $v['content'],
                        'created_at' => Carbon::now()->toDayDateTimeString()
                    ];
                    DB::connection($this->connect)->table($this->togetherGameNotice)->insert($insert);
                }
                unset($xtqjNotices);
                unset($v);
                unset($insert);
            }
            // //查询许愿池抽奖记录
            // $luckDrawNotices = DB::connection($this->connect)->table($this->luckDrawTable)->limit(5)->orderBy('created_at','DESC')->get();
            // $luckDrawNotices = objToArray($luckDrawNotices);
            // if(!empty($luckDrawNotices)){
            //     foreach($luckDrawNotices as $v){
            //         $insert = [
            //             'game_name' => '许愿池',
            //             'user_id' => $v['user_id'],
            //             'game_type' => 5,//游戏类型1=全家总动员 2=西天取经 3=开运装备 4=荒漠捕牛 5=许愿池
            //             'content' => $v['awards'],
            //             'created_at' => Carbon::now()->toDayDateTimeString()
            //         ];
            //         DB::connection($this->connect)->table($this->togetherGameNotice)->insert($insert);
            //     }
            //     unset($xtqjNotices);
            //     unset($v);
            //     unset($insert);
            // }
            //开运装备公告
            $equipNotices = DB::connection($this->activity)->table($this->equipNoticeTable)->limit(5)->orderBy('created_at','DESC')->get();
            $equipNotices = objToArray($equipNotices);
            if(!empty($equipNotices)){
                foreach($equipNotices as $v){
                    $insert = [
                        'game_name' => '开运装备星',
                        'user_id' => $v['user_id'],
                        'game_type' => 3,//游戏类型1=全家总动员 2=西天取经 3=开运装备 4=荒漠捕牛 5=许愿池
                        'content' => $v['content'],
                        'created_at' => Carbon::now()->toDayDateTimeString()
                    ];
                    DB::connection($this->connect)->table($this->togetherGameNotice)->insert($insert);
                }
                unset($xtqjNotices);
                unset($v);
                unset($insert);
            }
        }while(false);
    }
}